package com.health.activity.qyinfo;

import java.util.List;

import com.health.NovaApplication;
import com.health.R;
import com.health.adapter.QYAdapter2;
import com.health.fragment.NovaFragment;
import com.health.tablebean.JTYSDoctorContInfoBean;
import com.health.widget.MyListView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

/**
 * 签约服务项目包 （基础服务包）
 * 
 * @author nova
 *
 */
public class QY_fwxmb_jcFragment extends NovaFragment {

	private MyListView tongji_list_lv;
	private View baseView;
	QYAdapter2 adapter = null;
	List<JTYSDoctorContInfoBean> listFWXMs = null;

	@Override
	public View findViews(LayoutInflater inflater) {
		// userInfo = NovaApplication.userInfo;
		baseView = inflater.inflate(R.layout.qyinfo_qyxmb, null);
		findViews(baseView);
		// setListViewHeightBasedOnChildren(tongji_list_lv);
		addListener();
		setData();
		return baseView;
	}

	public boolean hasServicePackage() {
		if (listFWXMs != null) {
			if (!listFWXMs.isEmpty()) {
				return true;
			}
		}
		return false;
	}
	@Override
	public void setupView(View view) {

	}

	@Override
	public void addListener() {

	}

	public void setData() {
		if (((QYInfo) getActivity()).cont != null) {
			setCheckIDs(((QYInfo) getActivity()).cont.getDetailId());
		}

		// List<JTYSCustomerDoctorCont> conts =
		// NovaApplication.fdbmanger.findAllByWhere(JTYSCustomerDoctorCont.class,
		// "cardNum='" + NovaApplication.userInfo.getIDCARD() + "'");
		// if (conts.size() > 0) {
		//
		// }
	}

	public void findViews(View view) {
		tongji_list_lv = (MyListView) view.findViewById(R.id.tongji_list_lv);
		// View head = View.inflate(getActivity(), R.layout.qyinfo_list_head,
		// null);
		// tongji_list_lv.addHeaderView(head);
		// QYAdapter adapter =new
		// QYAdapter(getActivity().getApplicationContext(),QYAdapter.QYINFO_JC);
		// tongji_list_lv.setAdapter(adapter);
		listFWXMs = NovaApplication.fdbmanger.findAllByWhere(JTYSDoctorContInfoBean.class,
				"officeId='" + NovaApplication.getJgbh() + "' and contractServiceType='DM102-12_1'", "itemType");
		Log.e("基础服务包", listFWXMs.size()+"   机构编号"+NovaApplication.getJgbh());
		if (listFWXMs.size() > 0) {
			int flagSave = ((QYInfo) getActivity()).getFlagSave();
			adapter = new QYAdapter2(getActivity().getApplicationContext(), listFWXMs,flagSave);
			tongji_list_lv.setAdapter(adapter);
		}
	}

	public static void setListViewHeightBasedOnChildren(ListView listView) {
		if (listView == null)
			return;
		ListAdapter listAdapter = listView.getAdapter();
		if (listAdapter == null) {
			return;
		}
		int totalHeight = 0;
		for (int i = 0; i < listAdapter.getCount(); i++) {
			View listItem = listAdapter.getView(i, null, listView);
			listItem.measure(0, 0);
			totalHeight += listItem.getMeasuredHeight();
		}
		ViewGroup.LayoutParams params = listView.getLayoutParams();
		params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
		listView.setLayoutParams(params);

	}

	public String getCheckIDs() {
		if (adapter != null) {
			return adapter.getCheckedDatas();
		} else {
			return "";

		}
	}

	public void setCheckIDs(String ckids) {
		try {
			if (adapter != null) {
				adapter.setCheckedDatas(ckids);
				adapter.notifyDataSetChanged();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
